package com.dx.childrenedu.common;

import org.springframework.context.annotation.PropertySource;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * @ClassName Base64ConvertUtil
 * @Description TODO
 * @Author xst
 * @Date 2022/10/30 17:16
 * @Version 1.0
 **/
@PropertySource("classpath:config.properties")
public class Base64ConvertUtil {
    private Base64ConvertUtil() {}

    /**
     * 加密JDK1.8
     * @return java.lang.String
     * @author xst
     */
    public static String encode(String str) throws UnsupportedEncodingException {
        byte[] encodeBytes = Base64.getEncoder().encode(str.getBytes("utf-8"));
        return new String(encodeBytes);
    }

    /**
     * 解密JDK1.8
     * @return java.lang.String
     */
    public static String decode(String str) throws UnsupportedEncodingException {
        byte[] decodeBytes = Base64.getDecoder().decode(str.getBytes("utf-8"));
        return new String(decodeBytes);
    }

}
